﻿using AutoMapper;
using MediatR;
using S.Eartag.API.Application.Command.SheepFileConditionCommand;
using S.Eartag.Domain.Model;
using S.Eartag.Infrastructure.Impl;
using S.Eartag.Infrastructure.Interface;

namespace S.Eartag.API.Application.CommandHandlers.SheepFileConditionCommandHandler
{
    public class SheepFileConditionUpdateCommandHandler : IRequestHandler<SheepFileConditionUpdateCommand, int>
    {
        private readonly ISheepFileRepository sheepFileRepository;
        private readonly IMapper mapper;
        public SheepFileConditionUpdateCommandHandler(ISheepFileRepository sheepFileRepository, IMapper mapper)
        {
            this.sheepFileRepository = sheepFileRepository;
            this.mapper = mapper;
        }

        
        public async Task<int> Handle(SheepFileConditionUpdateCommand request, CancellationToken cancellationToken)
        {
            request.UpdateBy = "李四";
            request.UpdateDate = DateTime.Now;
            return await sheepFileRepository.Update(mapper.Map<SheepFile>(request));
        }
    }
}
